package com.example.service.friendship.controller;

import com.example.common.ResponseVO;
import com.example.common.model.SyncReq;
import com.example.service.friendship.model.req.*;
import com.example.service.friendship.service.ImFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("v1/friendship")
@Api(tags = "好友关系接口")
@Slf4j
public class ImFriendShipController {

    @Autowired
    ImFriendService imFriendShipService;

    @PostMapping("/importFriendShip")
    @ApiOperation(value = "导入好友关系")
    public ResponseVO importFriendShip(@RequestBody @Validated ImporFriendShipReq req){
        return imFriendShipService.importFriendShip(req);
    }

    @PostMapping("/addFriend")
    @ApiOperation(value = "添加好友")
    public ResponseVO addFriend(@RequestBody @Validated AddFriendReq req){ //,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.addFriend(req);
    }

    @PostMapping("/updateFriend")
    @ApiOperation(value = "修改好友")
    public ResponseVO updateFriend(@RequestBody @Validated UpdateFriendReq req){  //,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.updateFriend(req);
    }

    @DeleteMapping("/deleteFriend")
    @ApiOperation(value = "删除好友")
    public ResponseVO deleteFriend(@RequestBody @Validated DeleteFriendReq req){ //,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.deleteFriend(req);
    }

    @GetMapping("/getAllFriendShip")
    @ApiOperation(value = "获取所有的好友")
    public ResponseVO getAllFriendShip(@Validated GetAllFriendShipReq req){    //,Integer appId  extends RequestBase
        return imFriendShipService.getAllFriendShip(req);
    }

    @GetMapping("/getRelation")
    @ApiOperation(value = "获取两人关系")
    public ResponseVO getRelation(@RequestBody @Validated GetRelationReq req){ // ,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.getRelation(req);
    }

    @PostMapping("/checkFriend")
    @ApiOperation(value = "检查好友")   //通过toIds 进行进行 单向 或 双向 的检查  现在有单向好友和双向好友
    public ResponseVO checkFriend(@RequestBody @Validated CheckFriendShipReq req){  //,Integer appId  //        req.setAppId(appId);
        return imFriendShipService.checkFriendship(req);
    }

    @PostMapping("/addBlack")
    @ApiOperation(value = "添加黑名单")
    public ResponseVO addBlack(@RequestBody @Validated AddFriendShipBlackReq req ){ //,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.addBlack(req);
    }

    @PostMapping("/deleteBlack")
    @ApiOperation(value = "删除黑名单")
    public ResponseVO deleteBlack(@RequestBody @Validated DeleteBlackReq req ){ //,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.deleteBlack(req);
    }

    @GetMapping("/checkBlck")
    @ApiOperation(value = "查询黑名单")
    public ResponseVO checkBlck(@RequestBody @Validated CheckFriendShipReq req ){  //,Integer appId
//        req.setAppId(appId);
        return imFriendShipService.checkBlck(req);
    }


    @PostMapping("/syncFriendshipList")
    @ApiOperation(value = "同步好友列表(使用的是增量获取)")
    public ResponseVO syncFriendshipList(@RequestBody @Validated SyncReq req ){
        log.info(String.valueOf(req));    //这里不知到是什么情况在 syncreq 继承 RequestBase 在json 中写了 但传过来没有数值
        return imFriendShipService.syncFriendshipList(req);
    }





}
